﻿using Services.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Ionic_Server.Common
{
    //[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class CustomErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
            if (!filterContext.ExceptionHandled)
            {
                filterContext.ExceptionHandled = true;
                //返回异常JSON
                filterContext.Result = new JsonResult
                {
                    Data = new { Status = false, Message = filterContext.Exception.Message }
                };
            }



            //base.OnException(filterContext);
            ////错误记录
            ////LogHelper.WriteLog(JsonConvert.SerializeObject(msg, Formatting.Indented), null);

            ////设置为true阻止golbal里面的错误执行
            //filterContext.ExceptionHandled = true;
            //filterContext.Result = new JsonResult {
            //    Data = new ResponseBase<string> { Status = false, Exception = filterContext.Exception.Message } };

        }
    }

}